<?php 
# 文件名称:user.view.php
# MetInfo在线反馈系统 
# Copyright (C) 长沙米拓信息技术有限公司 (http://www.metinfo.cn). All rights reserved.
class userView extends C_view
{
	function userView()
	{
		parent::C_view();
	}
	//加载模板
	function display($tpl)
	{		
		$SYS = &get_instance();
		$class = $SYS->request->getVar('option', '', 'get');
		$class = $class==''?$SYS->request->getvar('option') : $class;
		$SYS->html->script('core.js');
		$this->assignRef('message', $SYS->loader->getMessageQueue());
		switch($class)
		{			
			case 'groups':$this->getGroups($tpl);break;
			default:$this->getUsers($tpl);
		}
	}
	//加载用户组模板
	function getGroups($tpl = null)
	{		
		$SYS = &get_instance();
		switch($tpl)
		{			
			case 'add':
							$SYS->request->setVar( 'cid', array(0));
							$this->assignRef('item', $this->get('GroupsItem'));
							$this->assignRef( 'subTitle',C_text::_('AddGroup'));
							$this->assignRef( 'options',$this->get('GroupsOptions'));
							$this->assign('apply', "add");
							$SYS->doc->addScriptDeclaration($this->validateGroup());
							$SYS->html->script('mootools-more.js');
							parent::display('user_groups_edit');break;
			case 'edit':								
							$this->assignRef('item', $this->get('GroupsItem'));
							$this->assign('apply', "edit");
							$this->assignRef( 'options',$this->get('GroupsOptions'));
							$this->assignRef( 'subTitle',C_text::_('EditGroup'));
							$SYS->doc->addScriptDeclaration($this->validateGroup());
							$SYS->html->script('mootools-more.js');
							parent::display('user_groups_edit');break;
			default:							
							$js_content="markRows();";
							$SYS->doc->addScriptDeclaration($js_content);
							$this->assignRef('items', $this->get('GroupsItems'));
							parent::display('user_groups');
		}
	}
	//加载用户模板
	function getUsers($tpl = null)
	{
		$SYS = &get_instance();
		$me = &$SYS->session->get('admin_name');
		$this->assignRef('me', 		$me);
		switch($tpl)
		{			
			case 'add':
							$user =& $SYS->user->getInstance( 0 );
							$lists['block'] = C_html::_('select.booleanlist',  'block', 'class="inputbox" size="1"', $user->get('block') );
							$this->assignRef( 'title', C_text::_('user add'));	
							$this->assignRef( 'subTitle',C_text::_('AddUser'));
							$this->assign('apply', "add");
							$this->assign('groups', array());
							$this->assignRef( 'lists', $lists);
							$this->assignRef('user',	$user);
							$SYS->html->script('usergroups.js');
							$SYS->doc->addScriptDeclaration($this->validateUser());
							parent::display('user_users_edit');break;
			case 'edit':							
							$this->assignRef( 'title', C_text::_('user edit'));
							$this->assignRef( 'subTitle',C_text::_('EditUser'));
							$this->assign('apply', "edit");
							$this->assignRef('user', $this->get('User'));
							$this->assignRef('groups', $this->get('UserGroups'));
							$SYS->html->script('usergroups.js');
							$SYS->doc->addScriptDeclaration($this->validateUser());
							parent::display('user_users_edit');break;
			default:
							$js_content="markRows();";
							$SYS->doc->addScriptDeclaration($js_content);
							$this->assignRef( 'title', C_text::_('user manager'));
							$this->assignRef( 'admin_list', $this->get('Users'));
							$this->assignRef( 'lists', $this->get('lists'));
							$this->assignRef( 'pagination', $this->get('Pagination'));
							parent::display('user_users');
		}
	}
	//加载js库
	function validateUser()
	{
		$jscontent = 
		'
		function submitbutton(pressbutton) {
			var form = document.adminForm;
			if (pressbutton == "cancel") {
				submitform( pressbutton );
				return;
			}
			var r = new RegExp("[\<|\>|\"|\'|\%|\;|\(|\)|\&]", "i");
			groups = document.getElementById("1group_1");
			// do field validation
			if (trim(form.admin_name.value) == "") {
				alert( "'.C_text::_('u_Tip1').'");
			} else if (form.admin_id.value == "") {
				alert( "'.C_text::_('u_Tip2').'");
			} else if (r.exec(form.admin_id.value) || form.admin_id.value.length < 2) {
				alert( "'.C_text::_('u_Tip3').'");
			} else if (trim(form.admin_email.value) == "") {
				alert( "'.C_text::_('u_Tip4').'" );
			} else if (!groups.checked) {
				alert( "'.C_text::_('u_Tip5').'");
			} else if (((trim(form.password.value) != "") || (trim(form.password2.value) != "")) && (form.password.value != form.password2.value)){
				alert( "'.C_text::_('u_Tip6').'" );
			} else {
				submitform( pressbutton );
			}
		}
		';
		return $jscontent;
	}
	//加载js库
	function validateGroup()
	{
		$jscontent = 
		'
		function submitbutton(pressbutton) {
			var form = document.adminForm;
			if (pressbutton == "cancel") {
				submitform( pressbutton );
				return;
			}
			id = document.getElementById("c_formparent_id");
			title = document.getElementById("c_form_grouptitle");
			
			// do field validation
			if (id && id.value == 0) {
				alert( "'.C_text::_('g_Tip1').'");
			} else if (trim(title.value) == "") {
				alert( "'.C_text::_('g_Tip2').'");			
			} else {
				submitform( pressbutton );
			}
		}
		window.addEvent("domready", function(){ 
			new Accordion($$(".pane-toggler"), 
			$$(".pane-slider"), 
			{
				onActive: function(toggler, i) 
				{ 
					toggler.addClass("pane-toggler-down");toggler.removeClass("pane-toggler"); 
				},
				onBackground: function(toggler, i) 
				{ 
					toggler.addClass("pane-toggler"); toggler.removeClass("pane-toggler-down"); 
				},
				duration: 300,opacity: false,alwaysHide: true
			}); 
		});
		function showActions()
		{
			var action=document.getElementById("showActions");
			if(document.adminForm.section_id.value==11)
				action.style.display="";
			else
				action.style.display="none";
		}
		';		
		return $jscontent;
	}
}
# 本程序是一个开源系统,使用时请你仔细阅读使用协议,商业用途请自觉购买商业授权.
# Copyright (C) 长沙米拓信息技术有限公司 (http://www.metinfo.cn). All rights reserved.
?>